package com.markedquilt.controller;
/*
 * PackageName: com.markedquilt.controller
 * ClassName:   ArticleController
 * Author:   zhang
 * Date:     Created in 2020/11/2
 * Description:
 * History:
 * <author>        <time>             <version>          <desc>
 * 作者姓名         修改时间            版本号              描述
 * zhang           2020/11/2      1.0
 */

import com.markedquilt.pojo.Article;
import com.markedquilt.service.ArticleService;
import com.markedquilt.vo.ArticleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Calendar;
import java.util.List;

/**
 * Title:
 * Project: springbootTask
 *
 * @author ZhangKe
 * Created on 2020/11/2
 */
@Controller
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/find/{id}")
    @ResponseBody
    public ArticleVo findById(@PathVariable("id") Integer id){
        ArticleVo articleVo = articleService.findById(id);
        return articleVo;
    }

    @RequestMapping("/findAll")
    @ResponseBody
    public ArticleVo findAll(){
        ArticleVo all = articleService.findAll();
        return all;
    }

    /**
     * 分页查找
     * @param page  当前页
     * @param rows  行数
     * @param model 模型
     * @return  页内数据
     */
    @RequestMapping("/findPage")
    public String findPage(@RequestParam(value = "page",defaultValue = "1") int page,
                           @RequestParam(value = "rows",defaultValue = "3") int rows,
                           Model model){
        ArticleVo articleVo = new ArticleVo();
        articleVo = articleService.findPagedAll(page, rows);
        model.addAttribute("articlevo",articleVo);
        return "client/index";
    }
}
